package api.ws.server.rocket.send;

import basic.common.rocket.MQTask;
import basic.common.rocket.Mq;
import basic.common.rocket.MqModel;
import basic.common.rocket.MqTaskExecutor;
import basic.common.ws.Message;
import basic.common.ws.UserContainer;
import basic.common.ws.WsCst;

import javax.annotation.Resource;

/**
 * @创建人 xiaojiancheng
 * @时间 2020/5/26
 * @描述 点对点消息的处理
 */
@Mq(topic = WsCst.TopicName.WS_SEND,tag = WsCst.MsgType.SEND_USER)
public class SendMsgConsumer implements MQTask {
    @Resource
    UserContainer userContainer;

    @Resource
    MqTaskExecutor executor;

    @Override
    public boolean execute(MqModel model, String msgId) {
        Message message = model.obj(Message.class);
        // TODO: 2020/10/7 数据库需要保存这条消息

        MqModel copy = model.copy();
        //  点对点的消息 需要回复给接收者
        copy.setTopic(WsCst.TopicName.WS_RECEIVE);
        copy.setTag(WsCst.MsgType.RECEIVE_USER);

        executor.publish(copy);
        return true;
    }
}
